package com.example.demo.controller;

import com.example.demo.Person;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/param")//类路径
@RestController
public class ParamController {
    @RequestMapping("/mm1")
    public String mm1(String ch){
        return "接收到参数: " + ch;
    }
    @RequestMapping("/m1")
    public String m1(String name){
        return "接收到参数name: "+ name;
    }

    @RequestMapping("/m2")
    public String m2(String name, Integer age){
        return "接收到参数name: "+ name + ",age: "+ age;
    }

    @RequestMapping("/m3")
    public String m3(String name, Integer age){
        return "接收到参数name: "+ name + ",age: "+ age;
    }

    @RequestMapping("/m4")
    public String m4(Person person){
        return "接收到参数person:"+person.toString();
    }

    @RequestMapping("/m5")
    public String m5(@RequestParam(value = "name",required = false) String username){
        return "接收到参数name: "+ username;
    }

    @RequestMapping("/m6")
    public String m6(String[] elem){
        return "接收到参数elem: " + Arrays.toString(elem) + ",长度: "+elem.length;
    }

    @RequestMapping("/m7")
    public String m7(@RequestParam (required = false) List<String> list){
        return "接收到参数list: " + list + ",长度: "+ list.size();
    }

    @RequestMapping("/m8")
    public String m8(@RequestBody Person person){
        return "接收的数据person: "+person.toString();
    }

    @RequestMapping("/m9/{userId}/{name}")
    public String m9(@PathVariable Integer userId,@PathVariable String name){
        return "userId: "+userId+ ",name: "+name;
    }

}
